import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _class, _class2;

import React from 'react';
import { Cascader, Form, Input, Modal, Select, Spin } from 'antd';
import { Bind } from 'lodash-decorators';
import Checkbox from 'components/Checkbox';
import Switch from 'components/Switch';
import intl from 'utils/intl';
import { CODE_UPPER } from 'utils/regExp';
var formItemLayout = {
  labelCol: {
    span: 6
  },
  wrapperCol: {
    span: 16
  }
};
var StorageDrawer = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(StorageDrawer, _React$PureComponent);

  var _super = _createSuper(StorageDrawer);

  function StorageDrawer() {
    _classCallCheck(this, StorageDrawer);

    return _super.apply(this, arguments);
  }

  _createClass(StorageDrawer, [{
    key: "handleOk",
    value: function handleOk() {
      var _this$props = this.props,
          form = _this$props.form,
          _this$props$initData = _this$props.initData,
          initData = _this$props$initData === void 0 ? {} : _this$props$initData,
          type = _this$props.type,
          _this$props$onOk = _this$props.onOk,
          onOk = _this$props$onOk === void 0 ? function (e) {
        return e;
      } : _this$props$onOk;
      form.validateFields(function (err, values) {
        if (!err) {
          onOk(_objectSpread(_objectSpread(_objectSpread({}, initData), values), {}, {
            storageType: type
          }));
        }
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          form = _this$props2.form,
          title = _this$props2.title,
          modalVisible = _this$props2.modalVisible,
          loading = _this$props2.loading,
          type = _this$props2.type,
          _this$props2$onCancel = _this$props2.onCancel,
          onCancel = _this$props2$onCancel === void 0 ? function (e) {
        return e;
      } : _this$props2$onCancel,
          _this$props2$initLoad = _this$props2.initLoading,
          initLoading = _this$props2$initLoad === void 0 ? false : _this$props2$initLoad,
          _this$props2$initData = _this$props2.initData,
          initData = _this$props2$initData === void 0 ? {} : _this$props2$initData,
          _this$props2$serverPr = _this$props2.serverProviderList,
          serverProviderList = _this$props2$serverPr === void 0 ? [] : _this$props2$serverPr,
          _this$props2$prefixSt = _this$props2.prefixStrategyList,
          prefixStrategyList = _this$props2$prefixSt === void 0 ? [] : _this$props2$prefixSt,
          _this$props2$microsof = _this$props2.microsoftEndpointList,
          microsoftEndpointList = _this$props2$microsof === void 0 ? [] : _this$props2$microsof;
      var storageCode = initData.storageCode,
          domain = initData.domain,
          accessKeyId = initData.accessKeyId,
          accessKeySecret = initData.accessKeySecret,
          appId = initData.appId,
          region = initData.region,
          bucketPrefix = initData.bucketPrefix,
          accessControl = initData.accessControl,
          prefixStrategy = initData.prefixStrategy,
          _initData$endPoint = initData.endPoint,
          endPoint = _initData$endPoint === void 0 ? '' : _initData$endPoint,
          _initData$defaultFlag = initData.defaultFlag,
          defaultFlag = _initData$defaultFlag === void 0 ? 0 : _initData$defaultFlag,
          _initData$createBucke = initData.createBucketFlag,
          createBucketFlag = _initData$createBucke === void 0 ? 1 : _initData$createBucke;
      var _form$getFieldDecorat = form.getFieldDecorator,
          getFieldDecorator = _form$getFieldDecorat === void 0 ? function (e) {
        return e;
      } : _form$getFieldDecorat;
      var initEndPoint = endPoint.match(/^(http|https)?:\/\/([\S]+)$/);
      var endPointBefore = getFieldDecorator('endPointBefore', {
        initialValue: "".concat(!initEndPoint ? 'http' : initEndPoint && initEndPoint[1], "://")
      })( /*#__PURE__*/React.createElement(Select, {
        style: {
          width: 90
        }
      }, /*#__PURE__*/React.createElement(Select.Option, {
        value: "http://"
      }, "http://"), /*#__PURE__*/React.createElement(Select.Option, {
        value: "https://"
      }, "https://")));
      return /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        wrapClassName: "ant-modal-sidebar-right",
        transitionName: "move-right",
        title: title,
        width: 820,
        visible: modalVisible,
        confirmLoading: loading,
        onCancel: onCancel,
        onOk: this.handleOk
      }, /*#__PURE__*/React.createElement(Spin, {
        spinning: initLoading
      }, /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('cfile.storage.model.storage.storageCode').d('存储编码')
      }, formItemLayout), getFieldDecorator('storageCode', {
        initialValue: storageCode,
        rules: [{
          pattern: CODE_UPPER,
          message: intl.get('cpaas.common.validation.codeUpper').d('全大写及数字，必须以字母、数字开头，可包含“-”、“_”、“.”、“/”')
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        typeCase: "upper",
        inputChinese: false,
        disabled: !!endPoint
      }))), /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('cfile.storage.model.storage.prefixStrategy').d('文件名前缀策略')
      }, formItemLayout), getFieldDecorator('prefixStrategy', {
        initialValue: prefixStrategy
      })( /*#__PURE__*/React.createElement(Select, {
        allowClear: true
      }, prefixStrategyList.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      })))), type !== '11' && /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: type === '6' || type === '2' || type === '3' || type === '4' ? intl.get('cfile.storage.model.storage.Domain2').d('代理地址') : intl.get('cfile.storage.model.storage.Domain').d('域名(Domain)')
      }, formItemLayout), getFieldDecorator('domain', {
        initialValue: domain,
        rules: [{
          required: type !== '2' && type !== '3' && type !== '4',
          message: intl.get('cpaas.common.validation.notNull', {
            name: type === '6' || type === '2' || type === '3' || type === '4' ? intl.get('cfile.storage.model.storage.Domain2').d('代理地址') : intl.get('cfile.storage.model.storage.Domain').d('域名(Domain)')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: // eslint-disable-next-line no-nested-ternary
        type === '6' ? intl.get('cfile.storage.model.storage.storageRoute').d('存储路径') : type === '11' ? intl.get('cfile.storage.model.storage.endPointMeaning').d('区域') : intl.get('cfile.storage.model.storage.EndPoint').d('EndPoint')
      }, formItemLayout), getFieldDecorator('endPoint', {
        initialValue: !initEndPoint || type !== '3' ? endPoint : initEndPoint && initEndPoint[2],
        rules: [{
          type: 'string',
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: type === '6' ? intl.get('cfile.storage.model.storage.storageRoute').d('存储路径') : intl.get('cfile.storage.model.storage.EndPoint').d('EndPoint')
          })
        }]
      })(type === '11' ? /*#__PURE__*/React.createElement(Select, {
        allowClear: true
      }, microsoftEndpointList.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      })) : /*#__PURE__*/React.createElement(Input, {
        addonBefore: type === '3' ? endPointBefore : null
      }))), type !== '6' && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('cfile.storage.model.storage.AccessKeyId').d('AccessKeyId')
      }, formItemLayout), getFieldDecorator('accessKeyId', {
        initialValue: accessKeyId,
        rules: [{
          type: 'string',
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cfile.storage.model.storage.AccessKeyId').d('AccessKeyId')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('cfile.storage.model.storage.accessKeySecret').d('AccessKeySecret')
      }, formItemLayout), getFieldDecorator('accessKeySecret', {
        initialValue: accessKeySecret,
        rules: [{
          type: 'string',
          required: false,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cfile.storage.model.storage.accessKeySecret').d('AccessKeySecret')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        type: "password",
        autocomplete: "new-password",
        placeholder: intl.get('cfile.storage.view.validation.notChange').d('未更改')
      })))), type === '4' && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('cfile.storage.model.storage.AppId').d('AppId')
      }, formItemLayout), getFieldDecorator('appId', {
        initialValue: appId,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cfile.storage.model.storage.AppId').d('AppId')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null)))), (type === '2' || type === '4' || type === '7' || type === '8') && /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('cfile.storage.model.storage.region').d('Bucket所属地区')
      }, formItemLayout), getFieldDecorator('region', {
        initialValue: region,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cfile.storage.model.storage.region').d('Bucket所属地区')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null))), type !== '6' && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('cfile.storage.model.storage.accessControl').d('bucket权限控制')
      }, formItemLayout), getFieldDecorator('accessControl', {
        initialValue: accessControl ? ["".concat(type), accessControl] : [],
        rules: [{
          type: 'array',
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cfile.storage.model.storage.accessControl').d('bucket权限控制')
          })
        }]
      })( /*#__PURE__*/React.createElement(Cascader, {
        placeholder: "",
        expandTrigger: "hover",
        allowClear: false,
        options: serverProviderList.filter(function (item) {
          if (type) {
            return item.value === type;
          } else {
            return item;
          }
        }),
        fieldNames: {
          label: 'meaning',
          value: 'value',
          children: 'children'
        }
      }))), /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('cfile.storage.model.storage.prefix').d('bucket前缀')
      }, formItemLayout), getFieldDecorator('bucketPrefix', {
        initialValue: bucketPrefix,
        rules: [type !== '3' && {
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cfile.storage.model.storage.prefix').d('bucket前缀')
          })
        }].filter(Boolean)
      })( /*#__PURE__*/React.createElement(Input, {
        inputChinese: false,
        typeCase: "lower"
      })))), type !== '6' && /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, formItemLayout, {
        label: intl.get('cfile.storage.model.storage.createBucketFlag').d('自动创建桶')
      }), form.getFieldDecorator('createBucketFlag', {
        initialValue: createBucketFlag
      })( /*#__PURE__*/React.createElement(Switch, null))), /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('cfile.storage.model.storage.defaultFlag').d('默认')
      }, formItemLayout), getFieldDecorator('defaultFlag', {
        initialValue: defaultFlag
      })( /*#__PURE__*/React.createElement(Checkbox, null))))));
    }
  }]);

  return StorageDrawer;
}(React.PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "handleOk", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "handleOk"), _class2.prototype)), _class2)) || _class);
export { StorageDrawer as default };